//
//  MyHouseViewController.m
//  YaDiuDiu
//
//  Created by 欧洪飞 on 2017/8/23.
//  Copyright © 2017年 jy. All rights reserved.
//

#import "MyHouseViewController.h"

#import "MyHouseCell.h"
#import "FirstView.h"
#import "SecondView.h"
#import "ThreeView.h"
#import "FourView.h"
#import "UpdateHouseViewController.h"
#import "SelectHouseTypeView.h"

#import "TZImagePickerController.h"

@interface MyHouseViewController ()<UITableViewDelegate,UITableViewDataSource,TZImagePickerControllerDelegate,UINavigationControllerDelegate, UIImagePickerControllerDelegate,UpdateHouseDelegate>{
    UILabel *labLine;
    UIScrollView *sclView;
    UIButton *btnR;
    UIButton *btnL;
    
    UIImageView *imageView;
    UILabel *labTit;
}

@property (nonatomic,strong)UITableView *tableView;

@property (nonatomic, strong) NSMutableArray *myHousingArray;

@property (nonatomic, strong) FirstView *oneView;

@property (nonatomic, strong) SecondView *twoView;

@property (nonatomic, strong) ThreeView *threeView;

@property (nonatomic, strong) FourView *fourView;

@property (nonatomic, strong) UIAlertController *sheet;

//=======Data

@property (nonatomic, strong) NSMutableArray *oneDataImageArray;

@end

@implementation MyHouseViewController

- (void)viewDidLoad {
    [super viewDidLoad];

    
    self.view.backgroundColor = COLOR_RGB(242, 242, 242, 1);
    
    [self loadNav];
    [self loadUI1];
    [self loadUI2];
    
    [self loadMyHousing];
    
}

- (void)loadNav{
    UIView *view = [[UIView alloc] initWithFrame:CGRectMake(0, 0, ScreenWidth, 64)];
    view.backgroundColor = [UIColor whiteColor];
    view.userInteractionEnabled = YES;
    [self.view addSubview:view];
    
    btnL = [UIButton buttonWithType:UIButtonTypeCustom];
    btnL.frame = CGRectMake(ScreenWidth/2-75, 30, 65, 25);
    btnL.titleLabel.font = [UIFont systemFontOfSize:15.0];
    //btnL.backgroundColor = [UIColor grayColor];
    [btnL setTitle:@"我的房源" forState:UIControlStateNormal];
    [btnL setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
    [btnL addTarget:self action:@selector(clickL) forControlEvents:UIControlEventTouchUpInside];
    btnL.titleLabel.font = [UIFont systemFontOfSize:15.0];
    [view addSubview:btnL];
    
    btnR = [UIButton buttonWithType:UIButtonTypeCustom];
    btnR.frame = CGRectMake(ScreenWidth/2+10, 30, 65, 25);
    btnR.titleLabel.font = [UIFont systemFontOfSize:15.0];
    //btnR.backgroundColor = [UIColor grayColor];
    [btnR setTitle:@"我的发布" forState:UIControlStateNormal];
    [btnR setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
    [btnR addTarget:self action:@selector(clickR) forControlEvents:UIControlEventTouchUpInside];
    btnR.titleLabel.font = [UIFont systemFontOfSize:15.0];
    [view addSubview:btnR];
    
    UIButton *btn = [UIButton buttonWithType:UIButtonTypeCustom];
    [btn setImage:[UIImage imageNamed:@"箭头"] forState:UIControlStateNormal];
    [btn addTarget:self action:@selector(clickBack) forControlEvents:UIControlEventTouchUpInside];
    [view addSubview:btn];
    [btn makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.equalTo(btnL.centerY);
        make.left.equalTo(0);
        make.width.equalTo(40);
        make.height.equalTo(40);
    }];
    
    labLine = [[UILabel alloc] initWithFrame:CGRectMake(btnL.frame.origin.x+18, 60, 30, 4)];
    labLine.backgroundColor = [UIColor redColor];
    labLine.layer.cornerRadius = 5.0;
    [view addSubview:labLine];
    
    self.sheet = [UIAlertController alertControllerWithTitle:nil message:nil preferredStyle:UIAlertControllerStyleActionSheet];
    UIAlertAction *cameraAction = [UIAlertAction actionWithTitle:@"相机" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
        BOOL ishave = [self doesCameraSupportTakingPhotos];
        if (ishave == YES) {
            UIImagePickerController *picker = [[UIImagePickerController alloc]init];
            picker.sourceType = UIImagePickerControllerSourceTypeCamera;
            picker.delegate = self;
            [self presentViewController:picker animated:YES completion:nil];
        }else{
            [LICGToast showWithText:@"相机不可用" bottomOffset:20 duration:5];
        }
    }];
    
    UIAlertAction *albumAction = [UIAlertAction actionWithTitle:@"相册" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
        BOOL ishave = [self isPhotoLibraryAvailable];
        if (ishave == YES) {
            TZImagePickerController *imagePC=[[TZImagePickerController alloc]initWithMaxImagesCount:6 delegate:self];
            [imagePC setDidFinishPickingPhotosHandle:^(NSArray<UIImage *> *imagarr, NSArray *array, BOOL bl) {
                UIImage *selimage = [imagarr firstObject];
                
                [self.oneView.poimage setHidden:YES];
                [self.oneView.zhulabel setHidden:YES];
                [self.oneView.updateLabel setHidden:YES];
                if (self.oneView.bgImageView.image == nil) {
                    [self.oneView.bgImageView setImage:selimage];
                }
                //async -- 并发队列
                dispatch_queue_t queue = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0);
                for (UIImage *itemImg in imagarr) {
                    dispatch_async(queue, ^{
                        [self uploadImage:itemImg];
                        NSLog(@"-----上传图片1---%@", [NSThread currentThread]);
                    });
                }
                
                
            }];
            [self presentViewController:imagePC animated:YES completion:nil];
        }else{
            [LICGToast showWithText:@"相册不可用" bottomOffset:20 duration:5];
        }
        
    }];
    
    UIAlertAction *cancelAction = [UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleCancel handler:^(UIAlertAction * _Nonnull action) {
        
    }];
    [self.sheet addAction:cancelAction];
    [self.sheet addAction:cameraAction];
    [self.sheet addAction:albumAction];
    
}

#pragma mark ====UIImagePickerControllerDelegate

- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info{
    UIImage *image = info[UIImagePickerControllerEditedImage];
    [self.oneView.poimage setHidden:YES];
    [self.oneView.zhulabel setHidden:YES];
    [self.oneView.updateLabel setHidden:YES];
    if (self.oneView.bgImageView.image == nil) {
        [self.oneView.bgImageView setImage:image];
    }
    [self uploadImage:image];
    [self dismissViewControllerAnimated:YES completion:nil];
}

- (void)uploadImage:(UIImage *)image{
    NSMutableDictionary *parmas = [NSMutableDictionary dictionary];
    [parmas setObject:@"pic.png" forKey:@"pic"];
    [parmas setObject:@"name" forKey:@"name"];
    AFHTTPRequestOperationManager *manager = [AFHTTPRequestOperationManager manager];
    manager.responseSerializer = [AFHTTPResponseSerializer serializer];
    NSString *url = [NSString stringWithFormat:@"%@/App/Norm/upload",urlHead];
    [manager POST:url parameters:parmas constructingBodyWithBlock:^(id<AFMultipartFormData> formData) {
        NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
        formatter.dateFormat = @"yyyy-MM-dd HH:mm:ss";
        NSString *fileName = [NSString stringWithFormat:@"%@.png",[formatter stringFromDate:[NSDate date]]];
        NSData *data = UIImageJPEGRepresentation(image, 0.5);
        [formData appendPartWithFileData:data name:@"pic" fileName:fileName mimeType:@"image/png"];
        [formData appendPartWithFileData:data name:@"name" fileName:fileName mimeType:@"image/png"];
        
    } success:^(AFHTTPRequestOperation *operation, id responseObject) {
        NSDictionary *op = [NSJSONSerialization JSONObjectWithData:responseObject options:kNilOptions error:nil];
        NSLog(@"dic:%@",op);
        NSInteger error =[[op objectForKey:@"error"] integerValue];
        if (error == 200) {
            NSString *imageString = [op objectForKey:@"result"];
            NSLog(@"imgUrl1:%@",imageString);
            [self.oneDataImageArray addObject:imageString];
        }
        
    } failure:^(AFHTTPRequestOperation *operation, NSError *error) {
        NSLog(@"error:%@",error);
    }];
}

- (void)loadMyHousing{
    [SVProgressHUD show];
    [SVProgressHUD setDefaultMaskType:SVProgressHUDMaskTypeBlack];
    NSMutableDictionary *parmas = [NSMutableDictionary dictionary];
    NSString *str = [NSString stringWithFormat:@"%@890d69e502d1d37a9e84335ccefece57",[user objectForKey:@"token2"]];
    NSString *token = [LCMD5Tool md5:str];
    [parmas setValue:token forKey:@"verifiToken"];
    [parmas setValue:[user objectForKey:@"userid"] forKey:@"userid"];
    
    NSString *url = [NSString stringWithFormat:@"%@/App/Rentout/myhousing",urlHead];
    [[AFHTTPSessionManager manager] POST:url parameters:parmas success:^(NSURLSessionDataTask *task, id responseObject) {
        NSLog(@"我的房源res:%@",responseObject);
        NSInteger state = [[responseObject objectForKey:@"error"] integerValue];
        NSString *msg = [responseObject objectForKey:@"mssage"];
        NSArray *resultArray = [responseObject objectForKey:@"result"];
        if (state == 200 && [resultArray isKindOfClass:[NSArray class]]) {
            self.myHousingArray  = [resultArray mutableCopy];
            [self.tableView reloadData];
            [self.tableView.mj_header endRefreshing];
            
            
            self.tableView.hidden = NO;
            imageView.hidden = YES;
            labTit.hidden = YES;
        }else{
            [self.tableView.mj_header endRefreshing];
            
            self.tableView.hidden = YES;
            imageView.hidden = NO;
            labTit.hidden = NO;
        }
        [SVProgressHUD dismiss];
        [LICGToast showWithText:msg];
    } failure:^(NSURLSessionDataTask *task, NSError *error) {
        NSLog(@"error:%@",error);
        [SVProgressHUD dismiss];
        [self.tableView.mj_header endRefreshing];
    }];
}

- (void)clickBack{
    [self.navigationController popViewControllerAnimated:YES];
}

- (void)clickL{
    [UIView animateWithDuration:0.3 animations:^{
        labLine.frame = CGRectMake(btnL.frame.origin.x+18, 60, 30, 4);
    }];
    _tableView.hidden = NO;
    sclView.hidden = YES;
}

- (void)clickR{
    [UIView animateWithDuration:0.3 animations:^{
        labLine.frame = CGRectMake(btnR.frame.origin.x+18, 60, 30, 4);
    }];
    _tableView.hidden = YES;
    sclView.hidden = NO;
}

- (void)loadUI1{
    _tableView = [[UITableView alloc] initWithFrame:CGRectMake(0, 64+10, ScreenWidth, ScreenHeight-64) style:UITableViewStylePlain];
    _tableView.delegate = self;
    _tableView.dataSource = self;
    _tableView.separatorStyle = UITableViewCellSelectionStyleNone;
    [_tableView setBackgroundColor:[UIColor clearColor]];
    [_tableView registerNib:[UINib nibWithNibName:@"MyHouseCell" bundle:[NSBundle mainBundle]] forCellReuseIdentifier:@"Cell"];
    [self.view addSubview:_tableView];
    self.tableView.mj_header = [MJRefreshNormalHeader headerWithRefreshingBlock:^{
        [self loadMyHousing];
    }];
    
    imageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"available"]];
    imageView.hidden = YES;
    [self.view addSubview:imageView];
    [imageView makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.equalTo(self.view.centerX);
        make.centerY.equalTo(self.view.centerY);
    }];
    
    labTit = [[UILabel alloc] init];
    labTit.text = @"暂无信息...";
    labTit.hidden = YES;
    labTit.font = [UIFont systemFontOfSize:15.0];
    labTit.textColor = [UIColor lightGrayColor];
    [self.view addSubview:labTit];
    [labTit makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.equalTo(self.view.centerX);
        make.top.equalTo(imageView.bottom).offset(8);
    }];
    
}

- (void)loadUI2{
    sclView = [[UIScrollView alloc] initWithFrame:CGRectMake(0, 64, ScreenWidth, ScreenHeight-64)];
    sclView.backgroundColor = COLOR_RGB(242, 242, 242, 1);
    sclView.contentSize = CGSizeMake(ScreenWidth, 1523);
    sclView.hidden = YES;
    [self.view addSubview:sclView];
    
    self.oneView = [[[NSBundle mainBundle] loadNibNamed:@"FirstView" owner:nil options:nil] lastObject];
    self.oneView.frame = CGRectMake(0, 0, ScreenWidth, 200);
    [sclView addSubview:self.oneView];
    
    
    self.twoView = [[[NSBundle mainBundle] loadNibNamed:@"SecondView" owner:nil options:nil] lastObject];
    self.twoView.frame = CGRectMake(0, self.oneView.frame.size.height+self.oneView.frame.origin.y+10, ScreenWidth, 300);
    [sclView addSubview:self.twoView];
    
    self.threeView = [[[NSBundle mainBundle] loadNibNamed:@"ThreeView" owner:nil options:nil] lastObject];
    self.threeView.frame = CGRectMake(0, self.twoView.frame.size.height+self.twoView.frame.origin.y+10, ScreenWidth, 293);
    [sclView addSubview:self.threeView];
    //500+293+640+50+40
    self.fourView = [[[NSBundle mainBundle] loadNibNamed:@"FourView" owner:nil options:nil] lastObject];
    self.fourView.frame = CGRectMake(0, self.threeView.frame.size.height+self.threeView.frame.origin.y+10, ScreenWidth, 640);
    [sclView addSubview:self.fourView];
    
    UIButton *btn = [UIButton buttonWithType:UIButtonTypeCustom];
    btn.frame = CGRectMake(0, self.fourView.frame.size.height+self.fourView.frame.origin.y+10, ScreenWidth, 50.0);
    [btn setTitle:@"确定发布" forState:UIControlStateNormal];
    [btn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    [btn setBackgroundColor:HexColorInt32_t(FD1142)];
    [btn addTarget:self action:@selector(submitEvent:) forControlEvents:UIControlEventTouchUpInside];
    [sclView addSubview:btn];
    
    __block typeof(self) bself = self;
    self.fourView.updateHeightAction = ^(NSInteger arrCount) {
        CGFloat height = (arrCount - 1) * 323;
        bself.fourView.frame = CGRectMake(0, self.threeView.frame.size.height+self.threeView.frame.origin.y+10, ScreenWidth, 640 + height);
        sclView.contentSize = CGSizeMake(ScreenWidth, 1523 + height);
        btn.frame = CGRectMake(0, self.fourView.frame.size.height + self.fourView.frame.origin.y + 10, ScreenWidth, 50.0);
    };
    
    self.oneView.addImageActionButton = ^(UIButton *sender) {
        if (self.oneDataImageArray.count < 6) {
            [bself presentViewController:bself.sheet animated:YES completion:nil];
        }
    };
}

-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    return self.myHousingArray.count;
}

-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    static NSString *cellId = @"Cell";
    MyHouseCell *cell = [tableView dequeueReusableCellWithIdentifier:cellId];
    if (!cell) {
        cell = [[[NSBundle mainBundle] loadNibNamed:@"MyHouseCell" owner:nil options:nil] lastObject];
    }
    cell.selectionStyle = UITableViewCellSelectionStyleNone;
    
    cell.btnDel.layer.cornerRadius = 5.0;
    cell.btnDel.layer.borderWidth = 1.0;
    cell.btnDel.layer.borderColor = [UIColor redColor].CGColor;
    
    cell.btnUpdate.layer.cornerRadius = 5.0;
    cell.btnUpdate.layer.borderWidth = 1.0;
    cell.btnUpdate.layer.borderColor = [UIColor redColor].CGColor;
    
    NSDictionary *itemDic = [self.myHousingArray objectAtIndex:indexPath.row];
    [cell setMyHouseData:itemDic];
    
    cell.deleteActionButton = ^(UIButton *sender) {
        [SVProgressHUD show];
        [SVProgressHUD setDefaultMaskType:SVProgressHUDMaskTypeBlack];
        NSMutableDictionary *parmas = [NSMutableDictionary dictionary];
        NSString *str = [NSString stringWithFormat:@"%@890d69e502d1d37a9e84335ccefece57",[user objectForKey:@"token2"]];
        NSString *token = [LCMD5Tool md5:str];
        
        NSString *fid = [itemDic objectForKey:@"id"];
        
        [parmas setValue:token forKey:@"verifiToken"];
        [parmas setValue:[user objectForKey:@"userid"] forKey:@"userid"];
        [parmas setValue:fid forKey:@"id"];
        
        NSString *url = [NSString stringWithFormat:@"%@/App/Rentout/delhous",urlHead];
        [[AFHTTPSessionManager manager] POST:url parameters:parmas success:^(NSURLSessionDataTask *task, id responseObject) {
            NSLog(@"删除房源res:%@",responseObject);
            NSInteger state = [[responseObject objectForKey:@"error"] integerValue];
            NSString *msg = [responseObject objectForKey:@"mssage"];
            if (state == 200 ) {
                [self.myHousingArray removeObjectAtIndex:indexPath.row];
                 [self.tableView deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:UITableViewRowAnimationLeft];
                [SVProgressHUD dismiss];
            }else{
                [SVProgressHUD showErrorWithStatus:msg];
            }
            
        } failure:^(NSURLSessionDataTask *task, NSError *error) {
            NSLog(@"error:%@",error);
            [SVProgressHUD dismiss];
        }];
    };
    
    cell.updateActionButton = ^(UIButton *sender) {
        UpdateHouseViewController *house = [[UpdateHouseViewController alloc] init];
        house.delegate = self;
        house.editDic = itemDic;
        [self.navigationController pushViewController:house animated:YES];
    };
    
    return cell;
}

-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    NSDictionary *itemDic = [self.myHousingArray objectAtIndex:indexPath.row];
    UpdateHouseViewController *house = [[UpdateHouseViewController alloc] init];
    house.delegate = self;
    house.editDic = itemDic;
    [self.navigationController pushViewController:house animated:YES];
}

-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    return 140.0;
}

-(void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event{
    [[UIApplication sharedApplication].keyWindow endEditing:YES];
}

- (NSMutableArray *)myHousingArray{
    if (!_myHousingArray) {
        _myHousingArray = [[NSMutableArray alloc]init];
    }
    return _myHousingArray;
}

- (void)submitEvent:(UIButton *)sender{
    NSString *topImageString = [self.oneDataImageArray componentsJoinedByString:@"|"];
    NSString *titleString = self.twoView.biaoTitle.text;
    NSString *zuPriceString = self.twoView.zuText.text;
    NSString *payString = self.twoView.payLabel.text;
    NSString *roomString = self.twoView.tingLabel.text;
    NSString *mianString = self.twoView.mianText.text;
    NSString *zuTypeString = self.twoView.zuTypeLabel.text;
    
    NSString *zhuangString = self.threeView.zhuangText.text;
    NSString *caoString = self.threeView.caoText.text;
    NSString *cengString = self.threeView.louText.text;
    NSString *yongString = self.threeView.yongText.text;
    NSString *huTypeString = self.threeView.typeText.text;
    NSString *cTime = self.threeView.yearsText.text;
    
    NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
    formatter.dateFormat = @"yyyy-MM-dd";
    NSString *addTime = [formatter stringFromDate:[NSDate date]];
    
    NSString *gaiString = self.fourView.gaishuLabel.text;
    NSString *tuwenSTtring = [self.fourView getImageAndTitleDataArray];
    
    if ([self isNullOrEmpty:topImageString]) {
        [LICGToast showWithText:@"请上传图片" bottomOffset:20 duration:5];
        return;
    }
    
    if ([self isNullOrEmpty:titleString]) {
        [LICGToast showWithText:@"请填写标题" bottomOffset:20 duration:5];
        return;
    }
    
    if ([self isNullOrEmpty:zuPriceString]) {
        [LICGToast showWithText:@"请填写租金" bottomOffset:20 duration:5];
        return;
    }
    
    if ([self isNullOrEmpty:payString]) {
        [LICGToast showWithText:@"请选择付款方式" bottomOffset:20 duration:5];
        return;
    }
    
    if ([self isNullOrEmpty:roomString]) {
        [LICGToast showWithText:@"请选择厅室" bottomOffset:20 duration:5];
        return;
    }
    
    if ([self isNullOrEmpty:mianString]) {
        [LICGToast showWithText:@"请填写面积" bottomOffset:20 duration:5];
        return;
    }
    
    if ([self isNullOrEmpty:zhuangString]) {
        [LICGToast showWithText:@"请选择装修" bottomOffset:20 duration:5];
        return;
    }
    
    if ([self isNullOrEmpty:caoString]) {
        [LICGToast showWithText:@"请选择朝向" bottomOffset:20 duration:5];
        return;
    }
    
    if ([self isNullOrEmpty:cengString]) {
        [LICGToast showWithText:@"请选择楼层" bottomOffset:20 duration:5];
        return;
    }
    
    if ([self isNullOrEmpty:yongString]) {
        [LICGToast showWithText:@"请选择用途" bottomOffset:20 duration:5];
        return;
    }
    
    if ([self isNullOrEmpty:huTypeString]) {
        [LICGToast showWithText:@"请选择户型" bottomOffset:20 duration:5];
        return;
    }
    
    if ([self isNullOrEmpty:cTime]) {
        [LICGToast showWithText:@"请选择建于时间" bottomOffset:20 duration:5];
        return;
    }
    
    if ([self isNullOrEmpty:gaiString]) {
        [LICGToast showWithText:@"请填写房源概述" bottomOffset:20 duration:5];
        return;
    }
    
    if ([self isNullOrEmpty:self.threeView.quText.text]) {
        [LICGToast showWithText:@"请选择小区" bottomOffset:20 duration:5];
        return;
    }
    
    if ([self isNullOrEmpty:tuwenSTtring]) {
        [LICGToast showWithText:@"请添加图文说明" bottomOffset:20 duration:5];
        return;
    }
    
    
    
    [SVProgressHUD show];
    [SVProgressHUD setDefaultMaskType:SVProgressHUDMaskTypeBlack];
    NSMutableDictionary *parmas = [[NSMutableDictionary alloc]init];
    NSString *str = [NSString stringWithFormat:@"%@890d69e502d1d37a9e84335ccefece57",[user objectForKey:@"token2"]];
    NSString *token = [LCMD5Tool md5:str];
    
    [parmas setValue:token forKey:@"verifiToken"];
    [parmas setValue:[user objectForKey:@"userid"] forKey:@"uid"];
    [parmas setValue:titleString forKey:@"title"];
    [parmas setValue:topImageString forKey:@"pic"];
    [parmas setValue:zuPriceString forKey:@"mnthly"];
    [parmas setValue:payString forKey:@"payment"];
    [parmas setValue:roomString forKey:@"room"];
    [parmas setValue:mianString forKey:@"area"];
    [parmas setValue:zuTypeString forKey:@"mode"];
    [parmas setValue:zhuangString forKey:@"rnovation"];
    [parmas setValue:caoString forKey:@"toward"];
    [parmas setValue:cengString forKey:@"floor"];
    [parmas setValue:yongString forKey:@"use"];
    [parmas setValue:huTypeString forKey:@"type"];
    [parmas setValue:cTime forKey:@"bilttime"];
    [parmas setValue:addTime forKey:@"reasetime"];
    [parmas setValue:gaiString forKey:@"text"];
    [parmas setValue:self.threeView.baiduInfo.name forKey:@"community"];
    [parmas setValue:@(self.threeView.baiduInfo.pt.longitude) forKey:@"longitude"];
    [parmas setValue:@(self.threeView.baiduInfo.pt.latitude) forKey:@"latitude"];
    [parmas setValue:tuwenSTtring forKey:@"teristic"];
    
    NSString *url = [NSString stringWithFormat:@"%@/App/Rentout/commentrent",urlHead];
    [[AFHTTPSessionManager manager] POST:url parameters:parmas success:^(NSURLSessionDataTask *task, id responseObject) {
        NSLog(@"发布房源res:%@",responseObject);
        NSInteger state = [[responseObject objectForKey:@"error"] integerValue];
        NSString *msg = [responseObject objectForKey:@"mssage"];
        if (state == 200) {
            [SVProgressHUD showSuccessWithStatus:msg];
        }else{
            [SVProgressHUD showErrorWithStatus:msg];
        }
        
    } failure:^(NSURLSessionDataTask *task, NSError *error) {
        NSLog(@"error:%@",error);
        [SVProgressHUD dismiss];
    }];
    
}

- (NSMutableArray *)oneDataImageArray{
    if (!_oneDataImageArray) {
        _oneDataImageArray = [[NSMutableArray alloc]init];
    }
    return _oneDataImageArray;
}

#pragma mark =====UpdateHouseDelegate
- (void)reloadDataList{
    [self myHousingArray];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
